home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tex / dvidoc.shar2 / dvidoc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-18  |  40.7 KB  |  1,825 lines

  1. /*
  2. ** The TeX text files device driver DVIDOC.WEB was originally written
  3. ** at OSU in April, 1983, by modifying the utility DVItype.
  4. ** Ken Yap (ken@cs.rochester.edu) modified it to work under 4.3 BSD.
  5. ** In January 1988 Neta Amit (amit@umn-cs.cs.umn.edu) tangle'd version-2
  6. ** (of July 1987). A little Icon program helped modify the resulting
  7. ** dvidoc.p into something acceptable to p2c, a Pascal-to-C transformer. 
  8. ** Dvidoc.c contained 3 errors that were fixed manually. 
  9. **
  10. ** Although the program was not tested extensively, theoretically it
  11. ** should behave just like the original dvidoc.
  12. */
  13. extern void    exit();
  14. /*
  15. **    Definitions for i/o
  16. */
  17. # include <stdio.h>
  18. typedef struct {
  19.     FILE    *fp;
  20.     unsigned short    eoln:1,
  21.             eof:1,
  22.             out:1,
  23.             init:1,
  24.             :12;
  25.     char    buf;
  26. }     text;
  27. text    input = { stdin, 0, 0 };
  28. text    output = { stdout, 0, 0 };
  29. # define Fread(x, f) fread((char *)&x, sizeof(x), 1, f)
  30. # define Get(f) Fread((f).buf, (f).fp)
  31. # define Getx(f) (f).init = 1, (f).eoln = (((f).buf = fgetc((f).fp)) == '\n') ? (((f).buf = ' '), 1) : 0
  32. # define Getchr(f) (f).buf, Getx(f)
  33. static FILE    *Tmpfil;
  34. static long    Tmplng;
  35. static double    Tmpdbl;
  36. # define Fscan(f) (f).init ? ungetc((f).buf, (f).fp) : 0, Tmpfil = (f).fp
  37. # define Scan(p, a) Scanck(fscanf(Tmpfil, p, a))
  38. void    Scanck();
  39. # define Fwrite(x, f) fwrite((char *)&x, sizeof(x), 1, f)
  40. # define Put(f) Fwrite((f).buf, (f).fp)
  41. # define Putx(f) (f).eoln = ((f).buf == '\n'), (void)fputc((f).buf, (f).fp)
  42. # define Putchr(c, f) (f).buf = (c), Putx(f)
  43. # define Putl(f, v) (f).eoln = v
  44. # define Finish(f) ((f).out && !(f).eoln) ? (Putchr('\n', f), 0) : 0, rewind((f).fp)
  45. # ifdef READONLY
  46. static char    Rmode[] = "r";
  47. # else
  48. static char    Rmode[] = "r+";
  49. # endif
  50. # define Reset(f, n) (f).init = (f).init ? rewind((f).fp) : (((f).fp = Fopen(n, Rmode)), 1), (f).eof = (f).out = 0, Get(f)
  51. # define Resetx(f, n) (f).init = (f).init ? (Finish(f)) : (((f).fp = Fopen(n, Rmode)), 1), (f).eof = (f).out = 0, Getx(f)
  52. # ifdef WRITEONLY
  53. static char    Wmode[] = "w";
  54. # else
  55. static char    Wmode[] = "w+";
  56. # endif
  57. # define Rewrite(f, n) (f).init = (f).init ? rewind((f).fp) : (((f).fp = Fopen(n, Wmode)), 1), (f).out = (f).eof = 1
  58. # define Rewritex(f, n) (f).init = (f).init ? (Finish(f)) : (((f).fp = Fopen(n, Wmode)), 1), (f).out = (f).eof = (f).eoln = 1
  59. FILE    *Fopen();
  60. # define MAXFILENAME 256
  61. /*
  62. **    Definitions for case-statements
  63. **    and for non-local gotos
  64. */
  65. # define Line __LINE__
  66. void    Caseerror();
  67. # include <setjmp.h>
  68. static struct Jb { jmp_buf    jb; } J[1];
  69. /*
  70. **    Definitions for standard types
  71. */
  72. typedef char    boolean;
  73. # define false (boolean)0
  74. # define true (boolean)1
  75. extern char    *Bools[];
  76. typedef int    integer;
  77. typedef double    real;
  78. extern double fabs();
  79. extern char *strncpy();
  80. /*
  81. **    Definitions for argv-operations
  82. */
  83. int    argc;
  84. char    **argv;
  85.  void
  86. Argvgt(n, cp, l)
  87. int    n;
  88. register int    l;
  89. register char    *cp;
  90. {
  91.     register char    *sp;
  92.  
  93.     for (sp = argv[n]; l > 0 && *sp; l--)
  94.         *cp++ = *sp++;
  95.     while (l-- > 0)
  96.         *cp++ = ' ';
  97. }
  98. /*
  99. **    Start of program definitions
  100. */
  101. # define maxfonts 100
  102. # define maxwidths 10000
  103. # define terminallinelength 150
  104. # define stacksize 100
  105. # define namesize 1000
  106. # define namelength 100
  107. # define pagewidthmax 132
  108. # define pagelengthmax 88
  109. typedef unsigned char    asciicode;
  110. typedef struct {
  111.     FILE    *fp;
  112.     unsigned short    eoln:1,
  113.             eof:1,
  114.             out:1,
  115.             init:1,
  116.             :12;
  117.     char    buf;
  118. }     textfile;
  119. typedef integer    eightbits;
  120. typedef struct {
  121.     FILE    *fp;
  122.     unsigned short    eoln:1,
  123.             eof:1,
  124.             out:1,
  125.             init:1,
  126.             :12;
  127.     char    buf;
  128. }     bytefile;
  129. typedef struct { asciicode    A[128]; }    T59;
  130. typedef struct { char    A[255 + 1]; }    T60;
  131. typedef struct { char    A[namelength - 1 + 1]; }    T61;
  132. typedef struct { integer    A[maxfonts + 1]; }    T62;
  133. typedef struct { unsigned short    A[maxfonts + 1]; }    T63;
  134. typedef struct { asciicode    A[namesize + 1]; }    T64;
  135. typedef struct { integer    A[maxfonts + 1]; }    T65;
  136. typedef struct { integer    A[maxfonts + 1]; }    T66;
  137. typedef struct { integer    A[maxfonts + 1]; }    T67;
  138. typedef struct { integer    A[maxfonts + 1]; }    T68;
  139. typedef struct { integer    A[maxfonts + 1]; }    T69;
  140. typedef struct { integer    A[maxfonts + 1]; }    T70;
  141. typedef struct { integer    A[maxfonts + 1]; }    T71;
  142. typedef struct { integer    A[maxwidths + 1]; }    T72;
  143. typedef struct { integer    A[255 + 1]; }    T73;
  144. typedef struct { integer    A[maxwidths + 1]; }    T74;
  145. typedef struct { integer    A[9 + 1]; }    T75;
  146. typedef struct { boolean    A[9 + 1]; }    T76;
  147. typedef struct { integer    A[9 + 1]; }    T77;
  148. typedef struct { asciicode    A[terminallinelength + 1]; }    T78;
  149. typedef struct { char    A[9 - 1 + 1]; }    T79;
  150. typedef struct { struct { asciicode    A[pagelengthmax - 1 + 1]; }    A[pagewidthmax - 1 + 1]; }    T80;
  151. typedef struct { unsigned char    A[pagelengthmax - 1 + 1]; }    T81;
  152. typedef struct { integer    A[stacksize + 1]; }    T82;
  153. typedef struct { integer    A[stacksize + 1]; }    T83;
  154. T59    xord;
  155. T60    xchr;
  156. bytefile    dvifile;
  157. boolean    eofdvifile;
  158. bytefile    tfmfile;
  159. integer    curloc;
  160. T61    basename, curname, realnameoffile;
  161. eightbits    b0, b1, b2, b3;
  162. T62    fontnum;
  163. T63    fontname;
  164. T64    names;
  165. T65    fontchecksum;
  166. T66    fontscaledsize;
  167. T67    fontdesignsize;
  168. T68    fontspace;
  169. T69    fontbc;
  170. T70    fontec;
  171. T71    widthbase;
  172. T72    width;
  173. unsigned char    nf;
  174. unsigned short    widthptr;
  175. T73    inwidth;
  176. integer    tfmchecksum;
  177. T74    pixelwidth;
  178. real    horizconv;
  179. real    vertconv;
  180. real    truehorizconv;
  181. real    truevertconv;
  182. integer    numerator, denominator;
  183. integer    mag;
  184. integer    maxpages;
  185. real    horizresolution;
  186. real    vertresolution;
  187. integer    newmag;
  188. T75    startcount;
  189. T76    startthere;
  190. unsigned char    startvals;
  191. T77    count;
  192. T78    buffer;
  193. unsigned char    bufptr;
  194. boolean    inpostamble;
  195. T79    defaultdirectory;
  196. unsigned char    i;
  197. boolean    logerrors;
  198. textfile    errfile;
  199. T80    pagebuffer;
  200. T81    linehwm;
  201. unsigned char    pagehwm;
  202. integer    h, v, w, x, y, z,
  203.     hh, vv;
  204. T82    hstack, vstack, wstack, xstack, ystack, zstack;
  205. T83    hhstack, vvstack;
  206. integer    maxv;
  207. integer    maxh;
  208. integer    maxs;
  209. integer    maxvsofar, maxhsofar, maxssofar;
  210. integer    totalpages;
  211. integer    pagecount;
  212. integer    s;
  213. integer    ss;
  214. integer    curfont;
  215. integer    oldbackpointer;
  216. integer    newbackpointer;
  217. boolean    started;
  218. integer    postloc;
  219. integer    firstbackpointer;
  220. integer    startloc;
  221. integer    k, m, n, p, q;
  222.  
  223. extern void opendvifile();
  224.  
  225. extern integer getbyte();
  226.  
  227. extern integer signedbyte();
  228.  
  229. extern integer gettwobytes();
  230.  
  231. extern integer signedpair();
  232.  
  233. extern integer getthreebytes();
  234.  
  235. extern integer signedtrio();
  236.  
  237. extern integer signedquad();
  238.  
  239. extern integer curpos();
  240.  
  241. extern void setpos();
  242.  
  243. extern void setpaths();
  244.  
  245. extern boolean testaccess();
  246.  
  247. extern void exit();
  248.  
  249.  void
  250. initialize()
  251. {
  252.     register integer    i;
  253.  
  254.     setpaths();
  255.     {
  256.         integer    B1 = 0,
  257.             B2 = 31;
  258.  
  259.         if (B1 <= B2)
  260.             for (i = B1; ; i++) {
  261.                 xchr.A[i] = '?';
  262.                 if (i == B2) break;
  263.             }
  264.     }
  265.     xchr.A[32] = ' ';
  266.     xchr.A[33] = '!';
  267.     xchr.A[34] = '"';
  268.     xchr.A[35] = '#';
  269.     xchr.A[36] = '$';
  270.     xchr.A[37] = '%';
  271.     xchr.A[38] = '&';
  272.     xchr.A[39] = '\'';
  273.     xchr.A[40] = '(';
  274.     xchr.A[41] = ')';
  275.     xchr.A[42] = '*';
  276.     xchr.A[43] = '+';
  277.     xchr.A[44] = ',';
  278.     xchr.A[45] = '-';
  279.     xchr.A[46] = '.';
  280.     xchr.A[47] = '/';
  281.     xchr.A[48] = '0';
  282.     xchr.A[49] = '1';
  283.     xchr.A[50] = '2';
  284.     xchr.A[51] = '3';
  285.     xchr.A[52] = '4';
  286.     xchr.A[53] = '5';
  287.     xchr.A[54] = '6';
  288.     xchr.A[55] = '7';
  289.     xchr.A[56] = '8';
  290.     xchr.A[57] = '9';
  291.     xchr.A[58] = ':';
  292.     xchr.A[59] = ';';
  293.     xchr.A[60] = '<';
  294.     xchr.A[61] = '=';
  295.     xchr.A[62] = '>';
  296.     xchr.A[63] = '?';
  297.     xchr.A[64] = '@';
  298.     xchr.A[65] = 'A';
  299.     xchr.A[66] = 'B';
  300.     xchr.A[67] = 'C';
  301.     xchr.A[68] = 'D';
  302.     xchr.A[69] = 'E';
  303.     xchr.A[70] = 'F';
  304.     xchr.A[71] = 'G';
  305.     xchr.A[72] = 'H';
  306.     xchr.A[73] = 'I';
  307.     xchr.A[74] = 'J';
  308.     xchr.A[75] = 'K';
  309.     xchr.A[76] = 'L';
  310.     xchr.A[77] = 'M';
  311.     xchr.A[78] = 'N';
  312.     xchr.A[79] = 'O';
  313.     xchr.A[80] = 'P';
  314.     xchr.A[81] = 'Q';
  315.     xchr.A[82] = 'R';
  316.     xchr.A[83] = 'S';
  317.     xchr.A[84] = 'T';
  318.     xchr.A[85] = 'U';
  319.     xchr.A[86] = 'V';
  320.     xchr.A[87] = 'W';
  321.     xchr.A[88] = 'X';
  322.     xchr.A[89] = 'Y';
  323.     xchr.A[90] = 'Z';
  324.     xchr.A[91] = '[';
  325.     xchr.A[92] = '\\';
  326.     xchr.A[93] = ']';
  327.     xchr.A[94] = '^';
  328.     xchr.A[95] = '_';
  329.     xchr.A[96] = '`';
  330.     xchr.A[97] = 'a';
  331.     xchr.A[98] = 'b';
  332.     xchr.A[99] = 'c';
  333.     xchr.A[100] = 'd';
  334.     xchr.A[101] = 'e';
  335.     xchr.A[102] = 'f';
  336.     xchr.A[103] = 'g';
  337.     xchr.A[104] = 'h';
  338.     xchr.A[105] = 'i';
  339.     xchr.A[106] = 'j';
  340.     xchr.A[107] = 'k';
  341.     xchr.A[108] = 'l';
  342.     xchr.A[109] = 'm';
  343.     xchr.A[110] = 'n';
  344.     xchr.A[111] = 'o';
  345.     xchr.A[112] = 'p';
  346.     xchr.A[113] = 'q';
  347.     xchr.A[114] = 'r';
  348.     xchr.A[115] = 's';
  349.     xchr.A[116] = 't';
  350.     xchr.A[117] = 'u';
  351.     xchr.A[118] = 'v';
  352.     xchr.A[119] = 'w';
  353.     xchr.A[120] = 'x';
  354.     xchr.A[121] = 'y';
  355.     xchr.A[122] = 'z';
  356.     xchr.A[123] = '{';
  357.     xchr.A[124] = '|';
  358.     xchr.A[125] = '}';
  359.     xchr.A[126] = '~';
  360.     {
  361.         integer    B3 = 127,
  362.             B4 = 255;
  363.  
  364.         if (B3 <= B4)
  365.             for (i = B3; ; i++) {
  366.                 xchr.A[i] = '?';
  367.                 if (i == B4) break;
  368.             }
  369.     }
  370.     {
  371.         integer    B5 = 0,
  372.             B6 = 127;
  373.  
  374.         if (B5 <= B6)
  375.             for (i = B5; ; i++) {
  376.                 xord.A[i] = 32;
  377.                 if (i == B6) break;
  378.             }
  379.     }
  380.     {
  381.         integer    B7 = 32,
  382.             B8 = 126;
  383.  
  384.         if (B7 <= B8)
  385.             for (i = B7; ; i++) {
  386.                 xord.A[xchr.A[i]] = i;
  387.                 if (i == B8) break;
  388.             }
  389.     }
  390.     nf = 0;
  391.     widthptr = 0;
  392.     fontname.A[0] = 0;
  393.     fontspace.A[0] = 0;
  394.     maxpages = 1000000;
  395.     startvals = 0;
  396.     startthere.A[0] = false;
  397.     inpostamble = false;
  398.     (void)strncpy(defaultdirectory.A, "TeXfonts:", sizeof(defaultdirectory.A));
  399.     maxv = 2147483548;
  400.     maxh = 2147483548;
  401.     maxs = stacksize + 1;
  402.     maxvsofar = 0;
  403.     maxhsofar = 0;
  404.     maxssofar = 0;
  405.     pagecount = 0;
  406.     oldbackpointer = -1;
  407.     started = false;
  408. }
  409.  
  410.  void
  411. jumpout()
  412. {
  413.     longjmp(J[0].jb, 9999);
  414. }
  415.  
  416.  void
  417. opentfmfile()
  418. {
  419.     if (testaccess(4, 3))
  420.         Resetx(tfmfile, realnameoffile.A);
  421.     else {
  422.         (void)fprintf(errfile.fp, "TFM file not found\n"), Putl(errfile, 1);
  423.         longjmp(J[0].jb, 30);
  424.     }
  425. }
  426.  
  427.  void
  428. readtfmword()
  429. {
  430.     char    byte;
  431.  
  432.     byte = Getchr(tfmfile);
  433.     b0 = (unsigned)(byte);
  434.     if (b0 < 0)
  435.         b0 = b0 + 256;
  436.     byte = Getchr(tfmfile);
  437.     b1 = (unsigned)(byte);
  438.     if (b1 < 0)
  439.         b1 = b1 + 256;
  440.     byte = Getchr(tfmfile);
  441.     b2 = (unsigned)(byte);
  442.     if (b2 < 0)
  443.         b2 = b2 + 256;
  444.     byte = Getchr(tfmfile);
  445.     b3 = (unsigned)(byte);
  446.     if (b3 < 0)
  447.         b3 = b3 + 256;
  448. }
  449.  
  450.  integer
  451. dvilength()
  452. {
  453.     register integer    R93;
  454.  
  455.     setpos(&dvifile, -1);
  456.     R93 = curpos(&dvifile);
  457.     return R93;
  458. }
  459.  
  460.  void
  461. movetobyte(n)
  462.     integer    n;
  463. {
  464.     setpos(&dvifile, n);
  465.     curloc = n;
  466. }
  467.  
  468.  void
  469. printfont(f)
  470.     integer    f;
  471. {
  472.     register unsigned short    k;
  473.  
  474.     if (f == nf)
  475.         (void)fprintf(errfile.fp, "UNDEFINED!"), Putl(errfile, 0);
  476.     else {
  477.         {
  478.             unsigned short    B9 = fontname.A[f],
  479.                 B10 = fontname.A[f + 1] - 1;
  480.  
  481.             if (B9 <= B10)
  482.                 for (k = B9; ; k++) {
  483.                     Putchr(xchr.A[names.A[k]], errfile);
  484.                     if (k == B10) break;
  485.                 }
  486.         }
  487.     }
  488. }
  489.  
  490.  boolean
  491. intfm(z)
  492.     integer    z;
  493. {
  494.     register boolean    R94;
  495.     register integer    k;
  496.     integer    lh;
  497.     integer    nw;
  498.     unsigned short    wp;
  499.     integer    alpha, beta;
  500.  
  501.     readtfmword();
  502.     lh = b2 * 256 + b3;
  503.     readtfmword();
  504.     fontbc.A[nf] = b0 * 256 + b1;
  505.     fontec.A[nf] = b2 * 256 + b3;
  506.     if (fontec.A[nf] < fontbc.A[nf])
  507.         fontbc.A[nf] = fontec.A[nf] + 1;
  508.     if (widthptr + fontec.A[nf] - fontbc.A[nf] + 1 > maxwidths) {
  509.         (void)fprintf(errfile.fp, "---not loaded, DVIDOC needs larger width table\n"), Putl(errfile, 1);
  510.         goto L9998;
  511.     }
  512.     wp = widthptr + fontec.A[nf] - fontbc.A[nf] + 1;
  513.     readtfmword();
  514.     nw = b0 * 256 + b1;
  515.     if ((nw == 0) || (nw > 256))
  516.         goto L9997;
  517.     {
  518.         integer    B11 = 1,
  519.             B12 = 3 + lh;
  520.  
  521.         if (B11 <= B12)
  522.             for (k = B11; ; k++) {
  523.                 if (eofdvifile)
  524.                     goto L9997;
  525.                 readtfmword();
  526.                 if (k == 4)
  527.                     if (b0 < 128)
  528.                         tfmchecksum = ((b0 * 256 + b1) * 256 + b2) * 256 + b3;
  529.                     else
  530.                         tfmchecksum = (((b0 - 256) * 256 + b1) * 256 + b2) * 256 + b3;
  531.                 if (k == B12) break;
  532.             }
  533.     }
  534.     if (wp > 0)
  535.         {
  536.             integer    B13 = widthptr,
  537.                 B14 = wp - 1;
  538.  
  539.             if (B13 <= B14)
  540.                 for (k = B13; ; k++) {
  541.                     readtfmword();
  542.                     if (b0 > nw)
  543.                         goto L9997;
  544.                     width.A[k] = b0;
  545.                     if (k == B14) break;
  546.                 }
  547.         }
  548.     {
  549.         alpha = 16 * z;
  550.         beta = 16;
  551.         while (z >= 8388608) {
  552.             z = z / 2;
  553.             beta = beta / 2;
  554.         }
  555.     }
  556.     {
  557.         integer    B15 = 0,
  558.             B16 = nw - 1;
  559.  
  560.         if (B15 <= B16)
  561.             for (k = B15; ; k++) {
  562.                 readtfmword();
  563.                 inwidth.A[k] = (((((b3 * z) / 256) + (b2 * z)) / 256) + (b1 * z)) / beta;
  564.                 if (b0 > 0)
  565.                     if (b0 < 255)
  566.                         goto L9997;
  567.                     else
  568.                         inwidth.A[k] = inwidth.A[k] - alpha;
  569.                 if (k == B16) break;
  570.             }
  571.     }
  572.     widthbase.A[nf] = widthptr - fontbc.A[nf];
  573.     if (wp > 0)
  574.         {
  575.             integer    B17 = widthptr,
  576.                 B18 = wp - 1;
  577.  
  578.             if (B17 <= B18)
  579.                 for (k = B17; ; k++) {
  580.                     width.A[k] = inwidth.A[width.A[k]];
  581.                     pixelwidth.A[k] = Round(horizconv * (width.A[k]));
  582.                     if (k == B18) break;
  583.                 }
  584.         }
  585.     widthptr = wp;
  586.     R94 = true;
  587.     goto L9999;
  588. L9997:
  589.     (void)fprintf(errfile.fp, "---not loaded, TFM file is bad\n"), Putl(errfile, 1);
  590. L9998:
  591.     R94 = false;
  592. L9999:
  593.     ;
  594.     return R94;
  595. }
  596.  
  597.  boolean
  598. startmatch()
  599. {
  600.     register boolean    R95;
  601.     register unsigned char    k;
  602.     boolean    match;
  603.  
  604.     match = true;
  605.     {
  606.         unsigned char    B19 = 0,
  607.             B20 = startvals;
  608.  
  609.         if (B19 <= B20)
  610.             for (k = B19; ; k++) {
  611.                 if (startthere.A[k] && (startcount.A[k] != count.A[k]))
  612.                     match = false;
  613.                 if (k == B20) break;
  614.             }
  615.     }
  616.     R95 = match;
  617.     return R95;
  618. }
  619.  
  620.  void
  621. copyln()
  622. {
  623.     unsigned char    k;
  624.  
  625.     k = 2;
  626.     while ((k < namelength) && (curname.A[k - 1] != ' ')) {
  627.         buffer.A[k - 3] = xord.A[curname.A[k - 1]];
  628.         k = k + 1;
  629.     }
  630.     buffer.A[k - 3] = xord.A[' '];
  631. }
  632.  
  633.  integer
  634. getinteger()
  635. {
  636.     register integer    R96;
  637.     integer    x;
  638.     boolean    negative;
  639.  
  640.     if (buffer.A[bufptr] == 45) {
  641.         negative = true;
  642.         bufptr = bufptr + 1;
  643.     } else
  644.         negative = false;
  645.     x = 0;
  646.     while ((buffer.A[bufptr] >= 48) && (buffer.A[bufptr] <= 57)) {
  647.         x = 10 * x + buffer.A[bufptr] - 48;
  648.         bufptr = bufptr + 1;
  649.     }
  650.     if (negative)
  651.         R96 = -x;
  652.     else
  653.         R96 = x;
  654.     return R96;
  655. }
  656.  
  657.  void
  658. options()
  659. {
  660.     integer    j, k;
  661.  
  662.     logerrors = false;
  663.     startvals = 0;
  664.     startthere.A[0] = false;
  665.     maxpages = 1000000;
  666.     horizresolution = 13.76582;
  667.     vertresolution = 6.0225;
  668.     newmag = 0;
  669.     basename.A[1 - 1] = ' ';
  670.     j = 1;
  671.     while (j < argc) {
  672.         Argvgt(j, curname.A, sizeof(curname.A));
  673.         if (curname.A[1 - 1] == '-') {
  674.             if (curname.A[2 - 1] == 'e')
  675.                 logerrors = true;
  676.             else
  677.                 if (curname.A[2 - 1] == 's') {
  678.                     copyln();
  679.                     bufptr = 0;
  680.                     k = 0;
  681.                     if (buffer.A[0] != 32)
  682.                         do {
  683.                             if (buffer.A[bufptr] == 42) {
  684.                                 startthere.A[k] = false;
  685.                                 bufptr = bufptr + 1;
  686.                             } else {
  687.                                 startthere.A[k] = true;
  688.                                 startcount.A[k] = getinteger();
  689.                             }
  690.                             if ((k < 9) && (buffer.A[bufptr] == 46)) {
  691.                                 k = k + 1;
  692.                                 bufptr = bufptr + 1;
  693.                             } else
  694.                                 if (buffer.A[bufptr] == 32)
  695.                                     startvals = k;
  696.                                 else {
  697.                                     (void)fprintf(stderr, "1.*.-5 specifies first page with \\count0=1, \\count2=-5.\n"), Putl(output, 1);
  698.                                     longjmp(J[0].jb, 30);
  699.                                 }
  700.                         } while (!(startvals == k));
  701.                 } else
  702.                     if (curname.A[2 - 1] == 'm') {
  703.                         copyln();
  704.                         bufptr = 0;
  705.                         if (buffer.A[0] != 32) {
  706.                             maxpages = getinteger();
  707.                             if (maxpages <= 0) {
  708.                                 (void)fprintf(stderr, "Maxpages should be a positive number.\n"), Putl(output, 1);
  709.                                 longjmp(J[0].jb, 30);
  710.                             }
  711.                         }
  712.                     } else {
  713.                         (void)fprintf(stderr, "Usage: dvidoc [-e] [-s<start page spec>] [-m<maxpages>] <dvi-file>\n"), Putl(output, 1);
  714.                         longjmp(J[0].jb, 30);
  715.                     }
  716.         } else
  717.             if (basename.A[1 - 1] == ' ')
  718.                 Argvgt(j, basename.A, sizeof(basename.A));
  719.             else {
  720.                 (void)fprintf(stderr, "Only one input file please\n"), Putl(output, 1);
  721.                 longjmp(J[0].jb, 30);
  722.             }
  723.         j = j + 1;
  724.     }
  725.     if (basename.A[1 - 1] == ' ') {
  726.         (void)fprintf(stderr, "No input file specified\n"), Putl(output, 1);
  727.         longjmp(J[0].jb, 30);
  728.     }
  729. }
  730.  
  731.  void
  732. definefont(e)
  733.     integer    e;
  734. {
  735.     unsigned char    f;
  736.     integer    p;
  737.     integer    n;
  738.     integer    c, q, d;
  739.     unsigned char    r;
  740.     unsigned short    j;
  741.     register unsigned short    k;
  742.     boolean    mismatch;
  743.  
  744.     if (nf == maxfonts) {
  745.         (void)fprintf(stderr, " DVIDOC capacity exceeded (max fonts=%1d)!\n", maxfonts), Putl(output, 1);
  746.         jumpout();
  747.     }
  748.     fontnum.A[nf] = e;
  749.     f = 0;
  750.     while (fontnum.A[f] != e)
  751.         f = f + 1;
  752.     c = signedquad();
  753.     fontchecksum.A[nf] = c;
  754.     q = signedquad();
  755.     fontscaledsize.A[nf] = q;
  756.     d = signedquad();
  757.     fontdesignsize.A[nf] = d;
  758.     p = getbyte();
  759.     n = getbyte();
  760.     if (fontname.A[nf] + n + p > namesize) {
  761.         (void)fprintf(stderr, " DVIDOC capacity exceeded (name size=%1d)!\n", namesize), Putl(output, 1);
  762.         jumpout();
  763.     }
  764.     fontname.A[nf + 1] = fontname.A[nf] + n + p;
  765.     (void)fprintf(errfile.fp, "Font %1d: ", e), Putl(errfile, 0);
  766.     if (n + p == 0)
  767.         (void)fprintf(errfile.fp, "null font name!"), Putl(errfile, 0);
  768.     else
  769.         {
  770.             unsigned short    B21 = fontname.A[nf],
  771.                 B22 = fontname.A[nf + 1] - 1;
  772.  
  773.             if (B21 <= B22)
  774.                 for (k = B21; ; k++) {
  775.                     names.A[k] = getbyte();
  776.                     if (k == B22) break;
  777.                 }
  778.         }
  779.     nf = nf + 1;
  780.     printfont(nf - 1);
  781.     nf = nf - 1;
  782.     if (inpostamble) {
  783.         if (f < nf)
  784.             (void)fprintf(errfile.fp, "---this font was already defined!\n"), Putl(errfile, 1);
  785.     } else {
  786.         if (f == nf)
  787.             (void)fprintf(errfile.fp, "---this font wasn't loaded before!\n"), Putl(errfile, 1);
  788.     }
  789.     if (f == nf) {
  790.         {
  791.             unsigned short    B23 = 1,
  792.                 B24 = namelength;
  793.  
  794.             if (B23 <= B24)
  795.                 for (k = B23; ; k++) {
  796.                     curname.A[k - 1] = ' ';
  797.                     if (k == B24) break;
  798.                 }
  799.         }
  800.         r = 0;
  801.         {
  802.             unsigned short    B25 = fontname.A[nf],
  803.                 B26 = fontname.A[nf + 1] - 1;
  804.  
  805.             if (B25 <= B26)
  806.                 for (k = B25; ; k++) {
  807.                     r = r + 1;
  808.                     if (r + 4 > namelength) {
  809.                         (void)fprintf(stderr, " DVIDOC capacity exceeded (max font name length=%1d)!\n", namelength), Putl(output, 1);
  810.                         jumpout();
  811.                     }
  812.                     curname.A[r - 1] = xchr.A[names.A[k]];
  813.                     if (k == B26) break;
  814.                 }
  815.         }
  816.         curname.A[r + 1 - 1] = '.';
  817.         curname.A[r + 2 - 1] = 't';
  818.         curname.A[r + 3 - 1] = 'f';
  819.         curname.A[r + 4 - 1] = 'm';
  820.         opentfmfile();
  821.         if (eofdvifile)
  822.             (void)fprintf(errfile.fp, "---not loaded, TFM file can't be opened!"), Putl(errfile, 0);
  823.         else {
  824.             if ((q <= 0) || (q >= 134217728))
  825.                 (void)fprintf(errfile.fp, "---not loaded, bad scale (%1d)!", q), Putl(errfile, 0);
  826.             else
  827.                 if ((d <= 0) || (d >= 134217728))
  828.                     (void)fprintf(errfile.fp, "---not loaded, bad design size (%1d)!", d), Putl(errfile, 0);
  829.                 else
  830.                     if (intfm(q)) {
  831.                         fontspace.A[nf] = q / 6;
  832.                         if ((c != 0) && (tfmchecksum != 0) && (c != tfmchecksum)) {
  833.                             (void)fprintf(errfile.fp, "---beware: check sums do not agree!\n"), Putl(errfile, 1);
  834.                             (void)fprintf(errfile.fp, "   (%1d vs. %1d)\n", c, tfmchecksum), Putl(errfile, 1);
  835.                             (void)fprintf(errfile.fp, "   "), Putl(errfile, 0);
  836.                         }
  837.                         (void)fprintf(errfile.fp, "---loaded at size %1d DVI units", q), Putl(errfile, 0);
  838.                         d = Round((100.0 * horizconv * q) / ((real)(truehorizconv * d)));
  839.                         if (d != 100) {
  840.                             Putchr(' ', errfile),Putchr('\n', errfile);
  841.                             (void)fprintf(errfile.fp, " (this font is magnified %1d%%)", d), Putl(errfile, 0);
  842.                         }
  843.                         nf = nf + 1;
  844.                         fontspace.A[nf] = 0;
  845.                     }
  846.         }
  847.         Putchr(' ', errfile),Putchr('\n', errfile);
  848.     } else {
  849.         if (fontchecksum.A[f] != c)
  850.             (void)fprintf(errfile.fp, "---check sum doesn't match previous definition!\n"), Putl(errfile, 1);
  851.         if (fontscaledsize.A[f] != q)
  852.             (void)fprintf(errfile.fp, "---scaled size doesn't match previous definition!\n"), Putl(errfile, 1);
  853.         if (fontdesignsize.A[f] != d)
  854.             (void)fprintf(errfile.fp, "---design size doesn't match previous definition!\n"), Putl(errfile, 1);
  855.         j = fontname.A[f];
  856.         k = fontname.A[nf];
  857.         mismatch = false;
  858.         while (j < fontname.A[f + 1]) {
  859.             if (names.A[j] != names.A[k])
  860.                 mismatch = true;
  861.             j = j + 1;
  862.             k = k + 1;
  863.         }
  864.         if (k != fontname.A[nf + 1])
  865.             mismatch = true;
  866.         if (mismatch)
  867.             (void)fprintf(errfile.fp, "---font name doesn't match previous definition!\n"), Putl(errfile, 1);
  868.         Putchr(' ', errfile),Putchr('\n', errfile);
  869.     }
  870. }
  871.  
  872.  void
  873. flushpage()
  874. {
  875.     register unsigned char    i;
  876.     register unsigned char    j;
  877.  
  878.     {
  879.         unsigned char    B27 = 1,
  880.             B28 = pagehwm;
  881.  
  882.         if (B27 <= B28)
  883.             for (j = B27; ; j++) {
  884.                 {
  885.                     unsigned char    B29 = 1,
  886.                         B30 = linehwm.A[j - 1];
  887.  
  888.                     if (B29 <= B30)
  889.                         for (i = B29; ; i++) {
  890.                             Putchr(xchr.A[pagebuffer.A[i - 1].A[j - 1]], output);
  891.                             if (i == B30) break;
  892.                         }
  893.                 }
  894.                 Putchr('\n', output);
  895.                 if (j == B28) break;
  896.             }
  897.     }
  898.     Putchr(12, output);
  899. }
  900.  
  901.  void
  902. emptypage()
  903. {
  904.     pagehwm = 0;
  905. }
  906.  
  907.  void
  908. outchar(p, hh, vv)
  909.     integer    p, hh, vv;
  910. {
  911.     unsigned char    i;
  912.     unsigned char    j;
  913.     register integer    k;
  914.     asciicode    c;
  915.  
  916.     if ((p > 32) && (p <= 126))
  917.         c = p;
  918.     else
  919.         c = xord.A['?'];
  920.     if ((hh > pagewidthmax - 1) || (vv > pagelengthmax - 1)) {
  921.         Putchr(' ', errfile),Putchr('\n', errfile);
  922.         (void)fprintf(errfile.fp, "Character \"%c\" set at column %1d", xchr.A[c], hh + 1), Putl(errfile, 0);
  923.         (void)fprintf(errfile.fp, " and row %1d,\n", vv + 1), Putl(errfile, 1);
  924.         (void)fprintf(errfile.fp, "outside the range of DVIDOC ("), Putl(errfile, 0);
  925.         (void)fprintf(errfile.fp, "%1d,%1d).", pagewidthmax, pagelengthmax), Putl(errfile, 0);
  926.         Putchr(' ', errfile),Putchr('\n', errfile);
  927.     } else {
  928.         i = hh + 1;
  929.         j = vv + 1;
  930.         if (j > pagehwm) {
  931.             {
  932.                 integer    B31 = pagehwm + 1,
  933.                     B32 = j;
  934.  
  935.                 if (B31 <= B32)
  936.                     for (k = B31; ; k++) {
  937.                         linehwm.A[k - 1] = 0;
  938.                         if (k == B32) break;
  939.                     }
  940.             }
  941.             pagehwm = j;
  942.         }
  943.         if (i > linehwm.A[j - 1]) {
  944.             {
  945.                 integer    B33 = linehwm.A[j - 1] + 1,
  946.                     B34 = i;
  947.  
  948.                 if (B33 <= B34)
  949.                     for (k = B33; ; k++) {
  950.                         pagebuffer.A[k - 1].A[j - 1] = xord.A[' '];
  951.                         if (k == B34) break;
  952.                     }
  953.             }
  954.             linehwm.A[j - 1] = i;
  955.         }
  956.         pagebuffer.A[i - 1].A[j - 1] = c;
  957.     }
  958. }
  959.  
  960.  integer
  961. firstpar(o)
  962.     eightbits    o;
  963. {
  964.     register integer    R97;
  965.  
  966.     switch (o) {
  967.       case 0:  case 1:  case 2:  case 3:
  968.       case 4:  case 5:  case 6:  case 7:
  969.       case 8:  case 9:  case 10:  case 11:
  970.       case 12:  case 13:  case 14:  case 15:
  971.       case 16:  case 17:  case 18:  case 19:
  972.       case 20:  case 21:  case 22:  case 23:
  973.       case 24:  case 25:  case 26:  case 27:
  974.       case 28:  case 29:  case 30:  case 31:
  975.       case 32:  case 33:  case 34:  case 35:
  976.       case 36:  case 37:  case 38:  case 39:
  977.       case 40:  case 41:  case 42:  case 43:
  978.       case 44:  case 45:  case 46:  case 47:
  979.       case 48:  case 49:  case 50:  case 51:
  980.       case 52:  case 53:  case 54:  case 55:
  981.       case 56:  case 57:  case 58:  case 59:
  982.       case 60:  case 61:  case 62:  case 63:
  983.       case 64:  case 65:  case 66:  case 67:
  984.       case 68:  case 69:  case 70:  case 71:
  985.       case 72:  case 73:  case 74:  case 75:
  986.       case 76:  case 77:  case 78:  case 79:
  987.       case 80:  case 81:  case 82:  case 83:
  988.       case 84:  case 85:  case 86:  case 87:
  989.       case 88:  case 89:  case 90:  case 91:
  990.       case 92:  case 93:  case 94:  case 95:
  991.       case 96:  case 97:  case 98:  case 99:
  992.       case 100:  case 101:  case 102:  case 103:
  993.       case 104:  case 105:  case 106:  case 107:
  994.       case 108:  case 109:  case 110:  case 111:
  995.       case 112:  case 113:  case 114:  case 115:
  996.       case 116:  case 117:  case 118:  case 119:
  997.       case 120:  case 121:  case 122:  case 123:
  998.       case 124:  case 125:  case 126:  case 127:
  999.         R97 = o - 0;
  1000.         break ;
  1001.       case 128:  case 133:  case 235:  case 239:
  1002.       case 243:
  1003.         R97 = getbyte();
  1004.         break ;
  1005.       case 129:  case 134:  case 236:  case 240:
  1006.       case 244:
  1007.         R97 = gettwobytes();
  1008.         break ;
  1009.       case 130:  case 135:  case 237:  case 241:
  1010.       case 245:
  1011.         R97 = getthreebytes();
  1012.         break ;
  1013.       case 143:  case 148:  case 153:  case 157:
  1014.       case 162:  case 167:
  1015.         R97 = signedbyte();
  1016.         break ;
  1017.       case 144:  case 149:  case 154:  case 158:
  1018.       case 163:  case 168:
  1019.         R97 = signedpair();
  1020.         break ;
  1021.       case 145:  case 150:  case 155:  case 159:
  1022.       case 164:  case 169:
  1023.         R97 = signedtrio();
  1024.         break ;
  1025.       case 131:  case 132:  case 136:  case 137:
  1026.       case 146:  case 151:  case 156:  case 160:
  1027.       case 165:  case 170:  case 238:  case 242:
  1028.       case 246:
  1029.         R97 = signedquad();
  1030.         break ;
  1031.       case 138:  case 139:  case 140:  case 141:
  1032.       case 142:  case 247:  case 248:  case 249:
  1033.       case 250:  case 251:  case 252:  case 253:
  1034.       case 254:  case 255:
  1035.         R97 = 0;
  1036.         break ;
  1037.       case 147:
  1038.         R97 = w;
  1039.         break ;
  1040.       case 152:
  1041.         R97 = x;
  1042.         break ;
  1043.       case 161:
  1044.         R97 = y;
  1045.         break ;
  1046.       case 166:
  1047.         R97 = z;
  1048.         break ;
  1049.       case 171:  case 172:  case 173:  case 174:
  1050.       case 175:  case 176:  case 177:  case 178:
  1051.       case 179:  case 180:  case 181:  case 182:
  1052.       case 183:  case 184:  case 185:  case 186:
  1053.       case 187:  case 188:  case 189:  case 190:
  1054.       case 191:  case 192:  case 193:  case 194:
  1055.       case 195:  case 196:  case 197:  case 198:
  1056.       case 199:  case 200:  case 201:  case 202:
  1057.       case 203:  case 204:  case 205:  case 206:
  1058.       case 207:  case 208:  case 209:  case 210:
  1059.       case 211:  case 212:  case 213:  case 214:
  1060.       case 215:  case 216:  case 217:  case 218:
  1061.       case 219:  case 220:  case 221:  case 222:
  1062.       case 223:  case 224:  case 225:  case 226:
  1063.       case 227:  case 228:  case 229:  case 230:
  1064.       case 231:  case 232:  case 233:  case 234:
  1065.         R97 = o - 171;
  1066.         break ;
  1067.       default:
  1068.         Caseerror(Line);
  1069.     }
  1070.     return R97;
  1071. }
  1072.  
  1073.  integer
  1074. horizrulepixels(x)
  1075.     integer    x;
  1076. {
  1077.     register integer    R98;
  1078.     integer    n;
  1079.  
  1080.     n = Trunc(horizconv * x);
  1081.     if (n < horizconv * x)
  1082.         R98 = n + 1;
  1083.     else
  1084.         R98 = n;
  1085.     return R98;
  1086. }
  1087.  
  1088.  integer
  1089. vertrulepixels(x)
  1090.     integer    x;
  1091. {
  1092.     register integer    R99;
  1093.     integer    n;
  1094.  
  1095.     n = Trunc(vertconv * x);
  1096.     if (n < vertconv * x)
  1097.         R99 = n + 1;
  1098.     else
  1099.         R99 = n;
  1100.     return R99;
  1101. }
  1102.  
  1103.  boolean
  1104. specialcases(o, p, a)
  1105.     eightbits    o;
  1106.     integer    p, a;
  1107. {
  1108.     register boolean    R100;
  1109.     integer    q;
  1110.     register integer    k;
  1111.     boolean    badchar;
  1112.     boolean    pure;
  1113.     integer    vvv;
  1114.  
  1115.     pure = true;
  1116.     switch (o) {
  1117.       case 133:  case 134:  case 135:  case 136:
  1118.         goto L30;
  1119.         break ;
  1120.       case 157:  case 158:  case 159:  case 160:
  1121.         if (abs(p) >= 5 * fontspace.A[curfont])
  1122.             vv = Round(vertconv * (v + p));
  1123.         else
  1124.             vv = vv + Round(vertconv * (p));
  1125.         goto L44;
  1126.         break ;
  1127.       case 161:  case 162:  case 163:  case 164:
  1128.       case 165:
  1129.         y = p;
  1130.         if (abs(p) >= 5 * fontspace.A[curfont])
  1131.             vv = Round(vertconv * (v + p));
  1132.         else
  1133.             vv = vv + Round(vertconv * (p));
  1134.         goto L44;
  1135.         break ;
  1136.       case 166:  case 167:  case 168:  case 169:
  1137.       case 170:
  1138.         z = p;
  1139.         if (abs(p) >= 5 * fontspace.A[curfont])
  1140.             vv = Round(vertconv * (v + p));
  1141.         else
  1142.             vv = vv + Round(vertconv * (p));
  1143.         goto L44;
  1144.         break ;
  1145.       case 171:  case 172:  case 173:  case 174:
  1146.       case 175:  case 176:  case 177:  case 178:
  1147.       case 179:  case 180:  case 181:  case 182:
  1148.       case 183:  case 184:  case 185:  case 186:
  1149.       case 187:  case 188:  case 189:  case 190:
  1150.       case 191:  case 192:  case 193:  case 194:
  1151.       case 195:  case 196:  case 197:  case 198:
  1152.       case 199:  case 200:  case 201:  case 202:
  1153.       case 203:  case 204:  case 205:  case 206:
  1154.       case 207:  case 208:  case 209:  case 210:
  1155.       case 211:  case 212:  case 213:  case 214:
  1156.       case 215:  case 216:  case 217:  case 218:
  1157.       case 219:  case 220:  case 221:  case 222:
  1158.       case 223:  case 224:  case 225:  case 226:
  1159.       case 227:  case 228:  case 229:  case 230:
  1160.       case 231:  case 232:  case 233:  case 234:
  1161.         goto L46;
  1162.         break ;
  1163.       case 235:  case 236:  case 237:  case 238:
  1164.         goto L46;
  1165.         break ;
  1166.       case 243:  case 244:  case 245:  case 246:
  1167.         definefont(p);
  1168.         goto L30;
  1169.         break ;
  1170.       case 239:  case 240:  case 241:  case 242:
  1171.         (void)fprintf(errfile.fp, "xxx'"), Putl(errfile, 0);
  1172.         badchar = false;
  1173.         {
  1174.             integer    B35 = 1,
  1175.                 B36 = p;
  1176.  
  1177.             if (B35 <= B36)
  1178.                 for (k = B35; ; k++) {
  1179.                     q = getbyte();
  1180.                     if ((q < 32) || (q > 126))
  1181.                         badchar = true;
  1182.                     Putchr(xchr.A[q], errfile);
  1183.                     if (k == B36) break;
  1184.                 }
  1185.         }
  1186.         Putchr('\'', errfile);
  1187.         if (badchar)
  1188.             (void)fprintf(errfile.fp, "non-ASCII character in xxx command!\n"), Putl(errfile, 1);
  1189.         goto L30;
  1190.         break ;
  1191.       case 247:
  1192.         (void)fprintf(errfile.fp, "preamble command within a page!\n"), Putl(errfile, 1);
  1193.         goto L9998;
  1194.         break ;
  1195.       case 248:  case 249:
  1196.         (void)fprintf(errfile.fp, "postamble command within a page!\n"), Putl(errfile, 1);
  1197.         goto L9998;
  1198.         break ;
  1199.       default:
  1200. {
  1201.             (void)fprintf(errfile.fp, "undefined command %1d!\n", o), Putl(errfile, 1);
  1202.             goto L30;
  1203.         }
  1204.     }
  1205. L44:
  1206.     if ((v > 0) && (p > 0))
  1207.         if (v > 2147483647 - p) {
  1208.             (void)fprintf(errfile.fp, "arithmetic overflow! parameter changed from %1d to %1d\n", p, 2147483647 - v), Putl(errfile, 1);
  1209.             p = 2147483647 - v;
  1210.         }
  1211.     if ((v < 0) && (p < 0))
  1212.         if (-v > p + 2147483647) {
  1213.             (void)fprintf(errfile.fp, "arithmetic overflow! parameter changed from %1d to %1d\n", p, (-v) - 2147483647), Putl(errfile, 1);
  1214.             p = (-v) - 2147483647;
  1215.         }
  1216.     vvv = Round(vertconv * (v + p));
  1217.     if (abs(vvv - vv) > 2)
  1218.         if (vvv > vv)
  1219.             vv = vvv - 2;
  1220.         else
  1221.             vv = vvv + 2;
  1222.     v = v + p;
  1223.     if (abs(v) > maxvsofar) {
  1224.         if (abs(v) > maxv + 99) {
  1225.             (void)fprintf(errfile.fp, "warning: |v|>%1d!\n", maxv), Putl(errfile, 1);
  1226.             maxv = abs(v);
  1227.         }
  1228.         maxvsofar = abs(v);
  1229.     }
  1230.     goto L30;
  1231. L46:
  1232.     fontnum.A[nf] = p;
  1233.     curfont = 0;
  1234.     while (fontnum.A[curfont] != p)
  1235.         curfont = curfont + 1;
  1236.     goto L30;
  1237. L9998:
  1238.     pure = false;
  1239. L30:
  1240.     R100 = pure;
  1241.     return R100;
  1242. }
  1243.  
  1244.  boolean
  1245. dopage()
  1246. {
  1247.     register boolean    R101;
  1248.     eightbits    o;
  1249.     integer    p, q;
  1250.     integer    a;
  1251.     register integer    j;
  1252.     register integer    i;
  1253.     integer    hhh;
  1254.  
  1255.     emptypage();
  1256.     curfont = nf;
  1257.     s = 0;
  1258.     h = 0;
  1259.     v = 0;
  1260.     w = 0;
  1261.     x = 0;
  1262.     y = 0;
  1263.     z = 0;
  1264.     hh = 0;
  1265.     vv = 0;
  1266.     while (true) {
  1267.         a = curloc;
  1268.         o = getbyte();
  1269.         p = firstpar(o);
  1270.         if (eofdvifile) {
  1271.             (void)fprintf(stderr, " Bad DVI file: the file ended prematurely!\n"), Putl(output, 1);
  1272.             jumpout();
  1273.         }
  1274.         if (o < 128) {
  1275.             outchar(p, hh, vv);
  1276.         } else
  1277.             switch (o) {
  1278.               case 128:  case 129:  case 130:  case 131:
  1279.                 outchar(p, hh, vv);
  1280.                 goto L41;
  1281.                 break ;
  1282.               case 132:
  1283.                 goto L42;
  1284.                 break ;
  1285.               case 137:
  1286.                 goto L42;
  1287.                 break ;
  1288.               case 138:
  1289.                 goto L30;
  1290.                 break ;
  1291.               case 139:
  1292.                 (void)fprintf(errfile.fp, "bop occurred before eop!\n"), Putl(errfile, 1);
  1293.                 goto L9998;
  1294.                 break ;
  1295.               case 140:
  1296.                 if (s != 0)
  1297.                     (void)fprintf(errfile.fp, "stack not empty at end of page (level %1d)!\n", s), Putl(errfile, 1);
  1298.                 R101 = true;
  1299.                 flushpage();
  1300.                 goto L9999;
  1301.                 break ;
  1302.               case 141:
  1303.                 if (s == maxssofar) {
  1304.                     maxssofar = s + 1;
  1305.                     if (s == maxs)
  1306.                         (void)fprintf(errfile.fp, "deeper than claimed in postamble!\n"), Putl(errfile, 1);
  1307.                     if (s == stacksize) {
  1308.                         (void)fprintf(errfile.fp, "DVIDOC capacity exceeded (stack size=%1d)\n", stacksize), Putl(errfile, 1);
  1309.                         goto L9998;
  1310.                     }
  1311.                 }
  1312.                 hstack.A[s] = h;
  1313.                 vstack.A[s] = v;
  1314.                 wstack.A[s] = w;
  1315.                 xstack.A[s] = x;
  1316.                 ystack.A[s] = y;
  1317.                 zstack.A[s] = z;
  1318.                 hhstack.A[s] = hh;
  1319.                 vvstack.A[s] = vv;
  1320.                 s = s + 1;
  1321.                 ss = s - 1;
  1322.                 goto L45;
  1323.                 break ;
  1324.               case 142:
  1325.                 if (s == 0)
  1326.                     (void)fprintf(errfile.fp, "Pop illegal at level zero!\n"), Putl(errfile, 1);
  1327.                 else {
  1328.                     s = s - 1;
  1329.                     hh = hhstack.A[s];
  1330.                     vv = vvstack.A[s];
  1331.                     h = hstack.A[s];
  1332.                     v = vstack.A[s];
  1333.                     w = wstack.A[s];
  1334.                     x = xstack.A[s];
  1335.                     y = ystack.A[s];
  1336.                     z = zstack.A[s];
  1337.                 }
  1338.                 ss = s;
  1339.                 goto L45;
  1340.                 break ;
  1341.               case 143:  case 144:  case 145:  case 146:
  1342.                 if (abs(p) >= fontspace.A[curfont]) {
  1343.                     hh = Round(horizconv * (h + p));
  1344.                 } else
  1345.                     hh = hh + Round(horizconv * (p));
  1346.                 q = p;
  1347.                 goto L43;
  1348.                 break ;
  1349.               case 147:  case 148:  case 149:  case 150:
  1350.               case 151:
  1351.                 w = p;
  1352.                 if (abs(p) >= fontspace.A[curfont]) {
  1353.                     hh = Round(horizconv * (h + p));
  1354.                 } else
  1355.                     hh = hh + Round(horizconv * (p));
  1356.                 q = p;
  1357.                 goto L43;
  1358.                 break ;
  1359.               case 152:  case 153:  case 154:  case 155:
  1360.               case 156:
  1361.                 x = p;
  1362.                 if (abs(p) >= fontspace.A[curfont]) {
  1363.                     hh = Round(horizconv * (h + p));
  1364.                 } else
  1365.                     hh = hh + Round(horizconv * (p));
  1366.                 q = p;
  1367.                 goto L43;
  1368.                 break ;
  1369.               default:
  1370.                 if (specialcases(o, p, a))
  1371.                     goto L30;
  1372.                 else
  1373.                     goto L9998;
  1374.             }
  1375.     L41:
  1376.         if (p < 0)
  1377.             p = 255 - ((-1 - p) % 256);
  1378.         else
  1379.             if (p >= 256)
  1380.                 p = p % 256;
  1381.         if ((p < fontbc.A[curfont]) || (p > fontec.A[curfont]))
  1382.             q = 2147483647;
  1383.         else
  1384.             q = width.A[widthbase.A[curfont] + p];
  1385.         if (q == 2147483647) {
  1386.             (void)fprintf(errfile.fp, "character %1d invalid in font \n", p), Putl(errfile, 1);
  1387.             printfont(curfont);
  1388.             if (curfont != nf)
  1389.                 Putchr('!', errfile);
  1390.         }
  1391.         if (o >= 133)
  1392.             goto L30;
  1393.         if (q == 2147483647)
  1394.             q = 0;
  1395.         else
  1396.             hh = hh + pixelwidth.A[widthbase.A[curfont] + p];
  1397.         goto L43;
  1398.     L42:
  1399.         q = signedquad();
  1400.         if ((p > 0) && (q > 0))
  1401.             {
  1402.                 integer    B37 = hh,
  1403.                     B38 = hh + horizrulepixels(q) - 1;
  1404.  
  1405.                 if (B37 <= B38)
  1406.                     for (i = B37; ; i++) {
  1407.                         {
  1408.                             integer    B39 = vv,
  1409.                                 B40 = vv - vertrulepixels(p) + 1;
  1410.  
  1411.                             if (B39 >= B40)
  1412.                                 for (j = B39; ; j--) {
  1413.                                     outchar(xord.A['-'], i, j);
  1414.                                     if (j == B40) break;
  1415.                                 }
  1416.                         }
  1417.                         if (i == B38) break;
  1418.                     }
  1419.             }
  1420.         if (o == 137)
  1421.             goto L30;
  1422.         hh = hh + horizrulepixels(q);
  1423.         goto L43;
  1424.     L43:
  1425.         if ((h > 0) && (q > 0))
  1426.             if (h > 2147483647 - q) {
  1427.                 (void)fprintf(errfile.fp, "arithmetic overflow! parameter changed from %1d to %1d\n", q, 2147483647 - h), Putl(errfile, 1);
  1428.                 q = 2147483647 - h;
  1429.             }
  1430.         if ((h < 0) && (q < 0))
  1431.             if (-h > q + 2147483647) {
  1432.                 (void)fprintf(errfile.fp, "arithmetic overflow! parameter changed from %1d to %1d\n", q, (-h) - 2147483647), Putl(errfile, 1);
  1433.                 q = (-h) - 2147483647;
  1434.             }
  1435.         hhh = Round(horizconv * (h + q));
  1436.         if (abs(hhh - hh) > 2)
  1437.             if (hhh > hh)
  1438.                 hh = hhh - 2;
  1439.             else
  1440.                 hh = hhh + 2;
  1441.         h = h + q;
  1442.         if (abs(h) > maxhsofar) {
  1443.             if (abs(h) > maxh + 99) {
  1444.                 (void)fprintf(errfile.fp, "warning: |h|>%1d!\n", maxh), Putl(errfile, 1);
  1445.                 maxh = abs(h);
  1446.             }
  1447.             maxhsofar = abs(h);
  1448.         }
  1449.         goto L30;
  1450.     L45:
  1451.         ;
  1452.     L30:
  1453.         ;
  1454.     }
  1455. L9998:
  1456.     Putchr('!', errfile),Putchr('\n', errfile);
  1457.     R101 = false;
  1458. L9999:
  1459.     ;
  1460.     return R101;
  1461. }
  1462.  
  1463.  void
  1464. readpostamble()
  1465. {
  1466.     integer    k;
  1467.     integer    p, q, m;
  1468.  
  1469.     postloc = curloc - 5;
  1470.     if (signedquad() != numerator)
  1471.         (void)fprintf(errfile.fp, "numerator doesn't match the preamble!\n"), Putl(errfile, 1);
  1472.     if (signedquad() != denominator)
  1473.         (void)fprintf(errfile.fp, "denominator doesn't match the preamble!\n"), Putl(errfile, 1);
  1474.     if (signedquad() != mag)
  1475.         if (newmag == 0)
  1476.             (void)fprintf(errfile.fp, "magnification doesn't match the preamble!\n"), Putl(errfile, 1);
  1477.     maxv = signedquad();
  1478.     maxh = signedquad();
  1479.     maxs = gettwobytes();
  1480.     totalpages = gettwobytes();
  1481.     do {
  1482.         k = getbyte();
  1483.         if ((k >= 243) && (k < 247)) {
  1484.             p = firstpar(k);
  1485.             definefont(p);
  1486.             Putchr(' ', errfile),Putchr('\n', errfile);
  1487.             k = 138;
  1488.         }
  1489.     } while (!(k != 138));
  1490.     if (k != 249)
  1491.         (void)fprintf(errfile.fp, "byte %1d is not postpost!\n", curloc - 1), Putl(errfile, 1);
  1492.     q = signedquad();
  1493.     if (q != postloc)
  1494.         (void)fprintf(errfile.fp, "bad postamble pointer in byte %1d!\n", curloc - 4), Putl(errfile, 1);
  1495.     m = getbyte();
  1496.     if (m != 2)
  1497.         (void)fprintf(errfile.fp, "identification in byte %1d should be %1d!\n", curloc - 1, 2), Putl(errfile, 1);
  1498.     k = curloc;
  1499.     m = 223;
  1500.     while ((m == 223) && !eofdvifile)
  1501.         m = getbyte();
  1502.     if (!eofdvifile) {
  1503.         (void)fprintf(stderr, " Bad DVI file: signature in byte %1d should be 223!\n", curloc - 1), Putl(output, 1);
  1504.         jumpout();
  1505.     } else
  1506.         if (curloc < k + 4)
  1507.             (void)fprintf(errfile.fp, "not enough signature bytes at end of file (%1d)\n", curloc - k), Putl(errfile, 1);
  1508. }
  1509.  
  1510. /*
  1511. **    Start of program code
  1512. */
  1513. main(_ac, _av)
  1514. int    _ac;
  1515. char    *_av[];
  1516. {
  1517.  
  1518.     argc = _ac;
  1519.     argv = _av;
  1520.     switch (setjmp(J[0].jb)) {
  1521.       case 0:
  1522.         break;
  1523.       case 9999:
  1524.         goto L9999;
  1525.       case 30:
  1526.         goto L30;
  1527.       default:
  1528.         Caseerror(Line);
  1529.     }
  1530.     initialize();
  1531.     options();
  1532.     i = 1;
  1533.     while ((i < namelength) && (basename.A[i - 1] != ' '))
  1534.         i = i + 1;
  1535.     if (i < 5) {
  1536.         basename.A[i - 1] = '.';
  1537.         basename.A[i + 1 - 1] = 'd';
  1538.         basename.A[i + 2 - 1] = 'v';
  1539.         basename.A[i + 3 - 1] = 'i';
  1540.         basename.A[i + 4 - 1] = ' ';
  1541.     }
  1542.     if ((i >= 5) && (i < namelength - 4) && ((basename.A[i - 4 - 1] != '.') || (basename.A[i - 3 - 1] != 'd') || (basename.A[i - 2 - 1] != 'v') || (basename.A[i - 1 - 1] != 'i'))) {
  1543.         basename.A[i - 1] = '.';
  1544.         basename.A[i + 1 - 1] = 'd';
  1545.         basename.A[i + 2 - 1] = 'v';
  1546.         basename.A[i + 3 - 1] = 'i';
  1547.         basename.A[i + 4 - 1] = ' ';
  1548.     }
  1549.     curname = basename;
  1550.     if (testaccess(4, 0)) {
  1551.         opendvifile();
  1552.         if (eofdvifile) {
  1553.             (void)fprintf(stderr, "Input file not found\n"), Putl(output, 1);
  1554.             goto L30;
  1555.         }
  1556.     } else {
  1557.         (void)fprintf(stderr, "Cannot open input file\n"), Putl(output, 1);
  1558.         goto L30;
  1559.     }
  1560.     if (logerrors) {
  1561.         curname = basename;
  1562.         i = 1;
  1563.         while ((i <= namelength) && (curname.A[i - 1] != ' '))
  1564.             i = i + 1;
  1565.         curname.A[i - 3 - 1] = 'e';
  1566.         curname.A[i - 2 - 1] = 'r';
  1567.         curname.A[i - 1 - 1] = 'r';
  1568.         if (testaccess(2, 0))
  1569.             Rewritex(errfile, curname.A);
  1570.         else {
  1571.             (void)fprintf(stderr, "Cannot create error file\n"), Putl(output, 1);
  1572.             goto L30;
  1573.         }
  1574.     } else {
  1575.         (void)strncpy(curname.A, "/dev/null", sizeof(curname.A));
  1576.         if (testaccess(2, 0))
  1577.             Rewritex(errfile, curname.A);
  1578.         else {
  1579.             (void)fprintf(stderr, "Somebody stole /dev/null!\n"), Putl(output, 1);
  1580.             goto L30;
  1581.         }
  1582.     }
  1583.     p = getbyte();
  1584.     if (p != 247) {
  1585.         (void)fprintf(stderr, " Bad DVI file: First byte isn't start of preamble!!\n"), Putl(output, 1);
  1586.         jumpout();
  1587.     }
  1588.     p = getbyte();
  1589.     if (p != 2)
  1590.         (void)fprintf(errfile.fp, "identification in byte 1 should be %1d!\n", 2), Putl(errfile, 1);
  1591.     numerator = signedquad();
  1592.     denominator = signedquad();
  1593.     if (numerator <= 0) {
  1594.         (void)fprintf(stderr, " Bad DVI file: numerator is %1d!\n", numerator), Putl(output, 1);
  1595.         jumpout();
  1596.     }
  1597.     if (denominator <= 0) {
  1598.         (void)fprintf(stderr, " Bad DVI file: denominator is %1d!\n", denominator), Putl(output, 1);
  1599.         jumpout();
  1600.     }
  1601.     horizconv = (numerator / ((real)254000.0)) * (horizresolution / ((real)denominator));
  1602.     vertconv = (numerator / ((real)254000.0)) * (vertresolution / ((real)denominator));
  1603.     mag = signedquad();
  1604.     if (newmag > 0)
  1605.         mag = newmag;
  1606.     else
  1607.         if (mag <= 0) {
  1608.             (void)fprintf(stderr, " Bad DVI file: magnification is %1d!\n", mag), Putl(output, 1);
  1609.             jumpout();
  1610.         }
  1611.     truehorizconv = horizconv;
  1612.     horizconv = truehorizconv * (mag / ((real)1000.0));
  1613.     truevertconv = vertconv;
  1614.     vertconv = truevertconv * (mag / ((real)1000.0));
  1615.     p = getbyte();
  1616.     Putchr('\'', errfile);
  1617.     while (p > 0) {
  1618.         p = p - 1;
  1619.         Putchr(xchr.A[getbyte()], errfile);
  1620.     }
  1621.     Putchr('\'', errfile),Putchr('\n', errfile);
  1622.     n = dvilength();
  1623.     if (n < 53) {
  1624.         (void)fprintf(stderr, " Bad DVI file: only %1d bytes long!\n", n), Putl(output, 1);
  1625.         jumpout();
  1626.     }
  1627.     m = n - 4;
  1628.     do {
  1629.         if (m == 0) {
  1630.             (void)fprintf(stderr, " Bad DVI file: all 223s!\n"), Putl(output, 1);
  1631.             jumpout();
  1632.         }
  1633.         movetobyte(m);
  1634.         k = getbyte();
  1635.         m = m - 1;
  1636.     } while (!(k != 223));
  1637.     if (k != 2) {
  1638.         (void)fprintf(stderr, " Bad DVI file: ID byte is %1d!\n", k), Putl(output, 1);
  1639.         jumpout();
  1640.     }
  1641.     movetobyte(m - 3);
  1642.     q = signedquad();
  1643.     if ((q < 0) || (q > m - 33)) {
  1644.         (void)fprintf(stderr, " Bad DVI file: post pointer %1d at byte %1d!\n", q, m - 3), Putl(output, 1);
  1645.         jumpout();
  1646.     }
  1647.     movetobyte(q);
  1648.     k = getbyte();
  1649.     if (k != 248) {
  1650.         (void)fprintf(stderr, " Bad DVI file: byte %1d is not post!\n", q), Putl(output, 1);
  1651.         jumpout();
  1652.     }
  1653.     postloc = q;
  1654.     firstbackpointer = signedquad();
  1655.     inpostamble = true;
  1656.     readpostamble();
  1657.     inpostamble = false;
  1658.     q = postloc;
  1659.     p = firstbackpointer;
  1660.     startloc = -1;
  1661.     if (p >= 0)
  1662.         do {
  1663.             if (p > q - 46) {
  1664.                 (void)fprintf(stderr, " Bad DVI file: page link %1d after byte %1d!\n", p, q), Putl(output, 1);
  1665.                 jumpout();
  1666.             }
  1667.             q = p;
  1668.             movetobyte(q);
  1669.             k = getbyte();
  1670.             if (k == 139)
  1671.                 pagecount = pagecount + 1;
  1672.             else {
  1673.                 (void)fprintf(stderr, " Bad DVI file: byte %1d is not bop!\n", q), Putl(output, 1);
  1674.                 jumpout();
  1675.             }
  1676.             {
  1677.                 integer    B41 = 0,
  1678.                     B42 = 9;
  1679.  
  1680.                 if (B41 <= B42)
  1681.                     for (k = B41; ; k++) {
  1682.                         count.A[k] = signedquad();
  1683.                         if (k == B42) break;
  1684.                     }
  1685.             }
  1686.             if (startmatch())
  1687.                 startloc = q;
  1688.             p = signedquad();
  1689.         } while (!(p < 0));
  1690.     if (startloc < 0) {
  1691.         (void)fprintf(stderr, " starting page number could not be found!\n"), Putl(output, 1);
  1692.         jumpout();
  1693.     }
  1694.     movetobyte(startloc + 1);
  1695.     oldbackpointer = startloc;
  1696.     {
  1697.         integer    B43 = 0,
  1698.             B44 = 9;
  1699.  
  1700.         if (B43 <= B44)
  1701.             for (k = B43; ; k++) {
  1702.                 count.A[k] = signedquad();
  1703.                 if (k == B44) break;
  1704.             }
  1705.     }
  1706.     p = signedquad();
  1707.     started = true;
  1708.     if (!inpostamble) {
  1709.         while (maxpages > 0) {
  1710.             maxpages = maxpages - 1;
  1711.             (void)fprintf(errfile.fp, "Page "), Putl(errfile, 0);
  1712.             {
  1713.                 integer    B45 = 0,
  1714.                     B46 = startvals;
  1715.  
  1716.                 if (B45 <= B46)
  1717.                     for (k = B45; ; k++) {
  1718.                         (void)fprintf(errfile.fp, "%1d", count.A[k]), Putl(errfile, 0);
  1719.                         if (k < startvals)
  1720.                             Putchr('.', errfile);
  1721.                         else
  1722.                             Putchr(' ', errfile),Putchr('\n', errfile);
  1723.                         if (k == B46) break;
  1724.                     }
  1725.             }
  1726.             if (!dopage()) {
  1727.                 (void)fprintf(stderr, " Bad DVI file: page ended unexpectedly!\n"), Putl(output, 1);
  1728.                 jumpout();
  1729.             }
  1730.             do {
  1731.                 k = getbyte();
  1732.                 if ((k >= 243) && (k < 247)) {
  1733.                     p = firstpar(k);
  1734.                     definefont(p);
  1735.                     k = 138;
  1736.                 }
  1737.             } while (!(k != 138));
  1738.             if (k == 248) {
  1739.                 inpostamble = true;
  1740.                 goto L30;
  1741.             }
  1742.             if (k != 139) {
  1743.                 (void)fprintf(stderr, " Bad DVI file: byte %1d is not bop!\n", curloc - 1), Putl(output, 1);
  1744.                 jumpout();
  1745.             }
  1746.             newbackpointer = curloc - 1;
  1747.             pagecount = pagecount + 1;
  1748.             {
  1749.                 integer    B47 = 0,
  1750.                     B48 = 9;
  1751.  
  1752.                 if (B47 <= B48)
  1753.                     for (k = B47; ; k++) {
  1754.                         count.A[k] = signedquad();
  1755.                         if (k == B48) break;
  1756.                     }
  1757.             }
  1758.             if (signedquad() != oldbackpointer)
  1759.                 (void)fprintf(errfile.fp, "backpointer in byte %1d should be %1d!\n", curloc - 4, oldbackpointer), Putl(errfile, 1);
  1760.             oldbackpointer = newbackpointer;
  1761.         }
  1762.     L30:
  1763.         ;
  1764.     }
  1765. L9999:
  1766.     ;
  1767.     exit(0);
  1768. }
  1769. /*
  1770. **    End of program code
  1771. */
  1772.  
  1773. static FILE *
  1774. Fopen(n, m)
  1775. char    *n, *m;
  1776. {
  1777.     FILE        *f;
  1778.     register char    *s;
  1779.     static char    ch = 'A';
  1780.     static char    tmp[MAXFILENAME];
  1781.     extern int    unlink();
  1782.  
  1783.     if (n == NULL)
  1784.         sprintf(tmp, "/tmp/ptc%d%c", getpid(), ch++);
  1785.     else {
  1786.         strncpy(tmp, n, sizeof(tmp));
  1787.         for (s = &tmp[sizeof(tmp)-1]; *s == ' ' || *s == '\0'; )
  1788.             *s-- = '\0';
  1789.         if (tmp[sizeof(tmp)-1]) {
  1790.             (void)fprintf(stderr, "Too long filename '%s'\n", n);
  1791.             exit(1);
  1792.         }
  1793.     }
  1794.     s = tmp;
  1795.     if ((f = fopen(s, m)) == NULL) {
  1796.         (void)fprintf(stderr, "Cannot open: %s\n", s);
  1797.         exit(1);
  1798.     }
  1799.     if (n == NULL)
  1800.         unlink(tmp);
  1801.     return (f);
  1802. }
  1803. extern int    rewind();
  1804.  
  1805. static void
  1806. Caseerror(n)
  1807.     int    n;
  1808. {
  1809.     (void)fprintf(stderr, "Missing case limb: line %d\n", n);
  1810.     exit(1);
  1811. }
  1812. static int
  1813. Trunc(f)
  1814. real    f;
  1815. {
  1816.     return f;
  1817. }
  1818. static int
  1819. Round(f)
  1820. real    f;
  1821. {
  1822.     extern double floor();
  1823.     return floor((double)(0.5+f));
  1824. }
  1825.